package com.zx.ishopping.mapper;

import com.zx.ishopping.annotation.AutoFill;
import com.zx.ishopping.entity.Cart;
import com.zx.ishopping.entity.CartItem;
import com.zx.ishopping.enums.OperationEnum;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface CartMapper {
    
  

    /**
     * 创建购物车
     * @param cart
     */
    @AutoFill(value = OperationEnum.INSERT)
    @Insert("INSERT  INTO carts (quantity,total_price,user_id) values (#{quantity},#{totalPrice},#{userId})")
    void createCart(Cart cart);


    /**
     * 通过用户id查询购物车信息
     * @param userId
     * @return
     */
    @Select("SELECT id,quantity,total_price from carts where user_id = #{userId}")
    Cart getCartInfo(Long userId);

    /**
     * 修改购物车信息
     * @param cartInfo
     */
    @AutoFill(value = OperationEnum.UPDATE)
    @Update("UPDATE carts SET quantity = #{quantity},total_price = #{totalPrice} where id = #{id} ")
    void update(Cart cartInfo);
}
